<?php

namespace App\Http\Controllers\Wechat;

use App\Http\Controllers\Controller;
use App\Models\Feedback;
use App\Models\Page;
use Illuminate\Http\Request;


class AboutController extends Controller
{
    // 常见问题
    public function problem()
    {
        return $this->writeJson(0, Page::whereGroup(2)->first());
    }

    // 关于我们
    public function me()
    {
        return $this->writeJson(0, Page::whereGroup(1)->first());
    }

    // 意见反馈
    public function feedback(Request $request)
    {
        try {
            $type_name = $request->post('type_name');
            if (!in_array($type_name, ['投诉', '建议'])) {
                return $this->writeJson(500, null, '反馈类型错误');
            }

            $model = new Feedback();
            $model->user_id = auth('wechat')->id();
            $model->type_name = $type_name;
            $model->content = $request->post('content');
            $model->phone = $request->post('phone');
            $model->save();
            return $this->writeJson(0, null, '反馈成功');
        } catch (\Exception $exception) {
            \Log::error($exception);
            return $this->writeJson(500, null, '反馈异常');
        }
    }
}
